package cn.kgc.dao;

import cn.kgc.pojo.User;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import javax.sql.DataSource;
import java.sql.SQLException;

/**
 * @author Rock
 * @create 2020-08-17 11:07
 */
public class UserDaoImpl implements UserDao {
    private DataSource ds=new ComboPooledDataSource();
    private QueryRunner queryRunner=new QueryRunner(ds) ;

    @Override
    public User getUserByUserName(String userName) {
        try {
            User user = queryRunner.query("select * from user where userName=?", new BeanHandler<User>(User.class), userName);
            return user;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
